package test.evaluator {
	import flash.display.Sprite;
	
	import org.kisekiproject.evaluator.Expression;
	import org.kisekiproject.evaluator.VariableStore;

	/**
	 * @author mikael
	 */
	public class ExpressionTest extends Sprite {

		/**
		 * Text function.
		 */
		public function myFunction(val:Number):Number {
			trace("the function was called, arg: "+val+" this: "+this);
			return val+1;
		}

		/**
		 * Text function.
		 */
		public function myOtherFunction():Number {
			trace("the other function was called");
			return 10;
		}

		/**
		 * Test expression evaluator.
		 */
		public function ExpressionTest() {
			var x:Expression;
			var v:VariableStore=new VariableStore();

//			x=new Expression("(1/2)*3",v);
//			x=new Expression("if (a==-10) 5 else if (a==9) 7 else 4",v);
//			x=new Expression("1+2+3",v);
//			x=new Expression("if (a==-10) 5",v);
//			x=new Expression("blugg.myFunction(a)",v);
//			x=new Expression("x(3).y(1).z(5)",v);
			x=new Expression("hello(2+world()+1)+5",v);

			v.setVariable("a",-10);
			v.setVariable("hello",myFunction);
			v.setVariable("world",myOtherFunction);
			v.setVariable("blugg",this);
			trace("result: "+x.value);
			v.setVariable("a",9);
			trace("result: "+x.value);
			v.setVariable("a",8);
			trace("result: "+x.value);
		}
	}
}
